<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        *{margin:0;padding:0}
        img{
            vertical-align: top;
        }
        .main{
            margin:0 auto;
            width:1000px;
            margin-top:10px;

        }
        .fixed {
            position: fixed;
            top: 0;
            left: 0;
        }
    </style>
    <script src="../../js/jquery.js"></script>
</head>
<body>
<div class="top" id="top">
    <img src="images/top.png" alt=""/>
</div>
<div id="Q-nav">
    <img src="images/nav.png" alt=""/>
</div>
<div class="main" id="main">
    <img src="images/main.png" alt=""/>
</div>
</body>
</html>

<script>
    $.fn.extend({
        fix(){
            $(document).on("scroll",function(){
                let $height=$(document).scrollTop()
                console.log($height);
                let $top=$(".top").outerHeight()
                console.log($top);
                if($height>=$top){
                    $("#Q-nav").addClass("fixed")
                }
                if($height<$top){
                    $("#Q-nav").removeClass("fixed")
                }
            })
        }
    })

    $(function(){
        $("#Q-nav").fix()
    })
</script>
